package DB;

import java.util.Vector;

public class DisjointProjection extends Projection {

/*
 * Constructor
 */
	
	public DisjointProjection(RAQuery raq,Vector<String> fields) {
		super(raq, fields);
	}

/*
 * @see DB.Projection#calcProb(int, DB.Table, java.util.Vector)
 * DisjointProjection calculates the probability by summing  
 * the probabilities of the matching tuples : p1 + p2 + p3 + ...
 */
	protected double calcProb(int index, Table t,Vector<String> currTuple) {
		double ans = t.getTupleProp(index);
		for (int i = index + 1 ; i < t.getSize(); i++ ){
			if (compareTuples(t, currTuple, t.getTuple(i))){
				ans +=  t.getTupleProp(i);
			}
		}
		if (ans > 1)
			return ans / t.getTotalProb();
		return ans;
	}	

}
